package com.wenhai.leetcode.tree;

/**
 * @ClassName _303区域和检索数组不可变
 * @Description https://leetcode-cn.com/problems/range-sum-query-immutable/
 * @Author 谢文海
 * @Date 2021/3/21 23:50
 * @Version 1.0
 **/
public class _303区域和检索数组不可变 {
    private final int[] sum;
    public _303区域和检索数组不可变(int[] nums) {
        this.sum = new int[nums.length + 1];
        this.sum[0] = 0;
        for (int i = 1; i < nums.length; i++) {
            sum[i] = sum[i - 1] + nums[i - 1];
        }

    }

    public int sumRange(int left, int right) {
        return sum[right + 1] - sum[left];
    }

}
